Skip to main content
PUT
/
api
/
detalles
/
{detalleId}
Update Order Item Quantity
curl --request PUT \
  --url https://api.example.com/api/detalles/{detalleId}
{
  "200": {},
  "204": {},
  "400": {},
  "401": {},
  "403": {},
  "404": {}
}

Authentication

This endpoint requires JWT authentication. Include the Bearer token in the Authorization header.

Path Parameters

detalleId
long
required
The unique identifier of the order detail (line item) to update

Query Parameters

cantidad
integer
required
New quantity for this line item. Must be a non-negative integer.
  • If set to 0, the line item will be deleted from the order
  • If greater than 0, the quantity will be updated

Response

Returns the updated order detail object with recalculated subtotal.
detalle_id
long
Unique identifier for this line item
producto_id
long
ID of the product
nombre
string
Product name
cantidad
integer
Updated quantity
precioUnitario
number
Price per unit (unchanged)
subtotal
number
Recalculated line total (cantidad × precioUnitario)

Example Requests

curl -X PUT "http://localhost:8080/api/detalles/45?cantidad=3" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"
JavaScript
// Update quantity
const response = await fetch(
  'http://localhost:8080/api/detalles/45?cantidad=3',
  {
    method: 'PUT',
    headers: {
      'Authorization': `Bearer ${token}`
    }
  }
);

if (response.status === 204) {
  console.log('Item removed from order');
} else {
  const updatedDetail = await response.json();
  console.log('New subtotal:', updatedDetail.subtotal);
}
Python
import requests

headers = {
    'Authorization': f'Bearer {token}'
}

# Update quantity to 5
response = requests.put(
    'http://localhost:8080/api/detalles/45',
    params={'cantidad': 5},
    headers=headers
)

if response.status_code == 204:
    print('Item removed')
else:
    detail = response.json()
    print(f'Updated quantity: {detail["cantidad"]}')

Example Response (Quantity > 0)

{
  "detalle_id": 45,
  "producto_id": 5,
  "nombre": "Sofá Klippan 2 plazas",
  "cantidad": 3,
  "precioUnitario": 299.00,
  "subtotal": 897.00
}

Status Codes

200
OK
Quantity updated successfully (when cantidad > 0)
204
No Content
Line item deleted successfully (when cantidad = 0)
400
Bad Request
Invalid quantity parameter (e.g., negative value, missing parameter)
401
Unauthorized
Missing or invalid JWT token
403
Forbidden
User does not have permission to modify this order
404
Not Found
Order detail with specified ID not found

Use Cases

  • Cart updates: Allow customers to adjust item quantities before checkout
  • Order corrections: Fix quantity mistakes in orders
  • Inventory adjustments: Modify order quantities based on stock availability
  • Bulk quantity changes: Update quantities programmatically
Setting quantity to 0 is an alternative way to remove an item from an order, equivalent to using the DELETE endpoint.
The unit price remains unchanged when updating quantity. Only the subtotal is recalculated.
Verify that the order status allows modifications before attempting to update quantities.